package 算法;

import com.sun.jmx.remote.internal.ArrayQueue;
import testJ.test1;

import java.util.Arrays;
import java.util.List;
import java.util.Queue;
import java.util.Stack;

public class 递归{
    public static int[] a;
    public static int k;
    public static int n;
    public static void main(String[] args) {
        //判断是否可以从中选出若于数，使它们的和恰好为k
//        a = new int[]{1,2,4,3};
//        k = 6;
//        n = a.length;
//        findStar(0,0,"");
        ListNode ln = new ListNode(1,new ListNode(2,new ListNode(3,new ListNode(4))));
        ListNode nl = swapPairs(ln);
        while (true){
            if(null == nl){
                break;
            }
            System.out.println(nl.val);
            nl = nl.next;
        }
    }
    //斐波那契数列 返回 对应的值
    static public int fei(int n){
        if(n == 1 || n == 2){
            return 1;
        }
        return fei(n-1)+fei(n-2);
    }
    //给定整数a1、a2、....、an ,判断是否可以从中选出若于数，使它们的和恰好为k
    //限制条件   1<=n<=20

    //如果 i == n 返回
    public static void findStar(int i,int sum,String st){
        if(i >= n){
            if(sum == k){
                System.out.println(st);
            }
            return;
        }
        //同意的时候
        findStar(i+1,sum+a[i],st+"->"+a[i]);
        //不同意的时候
        findStar(i+1,sum,st);
    }
    //返回的值是交换后的首节点
    public static ListNode swapPairs(ListNode head) {
        if(null == head || head.next == null){
            return head;
        }
        ListNode temp = head;
        head = head.next;
        temp.next = head.next;
        head.next = temp;

        temp.next = swapPairs(temp.next);
        return head;
    }
}
class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
